package com.hjm.project.InvoiceRecord.InvoiceRecord.controller;

import java.util.List;

import com.hjm.project.InvoiceRecord.InvoiceRecord.service.IInvoiceRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.InvoiceRecord.InvoiceRecord.domain.InvoiceRecord;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 服务商提供发票记录Controller
 * 
 * @author InvoiceRecord
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/InvoiceRecord/InvoiceRecord")
public class InvoiceRecordController extends BaseController
{
    private String prefix = "InvoiceRecord/InvoiceRecord";

    @Autowired
    private IInvoiceRecordService invoiceRecordService;

    @RequiresPermissions("InvoiceRecord:InvoiceRecord:view")
    @GetMapping()
    public String InvoiceRecord()
    {
        return prefix + "/InvoiceRecord";
    }

    @GetMapping("/InvoiceRecordIndex")
    public String InvoiceRecordIndex()
    {
        return prefix + "/InvoiceRecordIndex";
    }

    /**
     * 查询服务商提供发票记录列表（申请记录）
     */
    @RequiresPermissions("InvoiceRecord:InvoiceRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InvoiceRecord invoiceRecord)
    {
        startPage();
        //发票申请记录
        invoiceRecord.setStatus(Long.parseLong("1"));
        List<InvoiceRecord> list = invoiceRecordService.selectInvoiceRecordList(invoiceRecord);
        return getDataTable(list);
    }

    /**
     * 查询服务商提供发票记录列表（完成记录）
     */
    @RequiresPermissions("InvoiceRecord:InvoiceRecord:list")
    @PostMapping("/InvoiceRecordList")
    @ResponseBody
    public TableDataInfo InvoiceRecordList(InvoiceRecord invoiceRecord)
    {
        startPage();
        //发票完成记录
        invoiceRecord.setStatus(Long.parseLong("3"));
        List<InvoiceRecord> list = invoiceRecordService.selectInvoiceRecordList(invoiceRecord);
        return getDataTable(list);
    }

    /**
     * 导出服务商提供发票记录列表
     */
    @RequiresPermissions("InvoiceRecord:InvoiceRecord:export")
    @Log(title = "服务商提供发票记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InvoiceRecord invoiceRecord)
    {
        List<InvoiceRecord> list = invoiceRecordService.selectInvoiceRecordList(invoiceRecord);
        ExcelUtil<InvoiceRecord> util = new ExcelUtil<InvoiceRecord>(InvoiceRecord.class);
        return util.exportExcel(list, "InvoiceRecord");
    }

    /**
     * 新增服务商提供发票记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务商提供发票记录
     */
    @RequiresPermissions("InvoiceRecord:InvoiceRecord:add")
    @Log(title = "服务商提供发票记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InvoiceRecord invoiceRecord)
    {
        return toAjax(invoiceRecordService.insertInvoiceRecord(invoiceRecord));
    }

    /**
     * 修改服务商提供发票记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        InvoiceRecord invoiceRecord = invoiceRecordService.selectInvoiceRecordById(id);
        mmap.put("invoiceRecord", invoiceRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务商提供发票记录
     */
    @RequiresPermissions("InvoiceRecord:InvoiceRecord:edit")
    @Log(title = "服务商提供发票记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InvoiceRecord invoiceRecord)
    {
        return toAjax(invoiceRecordService.updateInvoiceRecord(invoiceRecord));
    }

    /**
     * 删除服务商提供发票记录
     */
    @RequiresPermissions("InvoiceRecord:InvoiceRecord:remove")
    @Log(title = "服务商提供发票记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(invoiceRecordService.deleteInvoiceRecordByIds(ids));
    }
}
